package com.notelapierdas.objects;

import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;

import com.notelapierdas.db.DBHelper;
import com.notelapierdas.db.DealDB;

public class Deal implements Parcelable{
	
	private Title title;
	private Price price;
	private ParcelableDate ending_time;
	private String conditions;
	private String highlights;
	private Business business;
	private Bitmap picture;
	
	public Deal(Title title,Price price, ParcelableDate date, String conditions, String highlights, Business business, Bitmap picture){
		this.title = title;
		this.price = price;
		this.ending_time = date;
		this.conditions = conditions;
		this.highlights = highlights;
		this.business = business;
		this.picture = picture;
	}
	
	public Deal(Parcel in) {
		readFromParcel(in);
	}


	public Title getTitle() {
		return title;
	}

	public void setTitle(Title title) {
		this.title = title;
	}

	

	public Price getPrice() {
		return price;
	}

	public void setPrice(Price price) {
		this.price = price;
	}

	public ParcelableDate getEnding_time() {
		return ending_time;
	}

	public void setEnding_time(ParcelableDate ending_time) {
		this.ending_time = ending_time;
	}

	public String getConditions() {
		return conditions;
	}

	public void setConditions(String conditions) {
		this.conditions = conditions;
	}

	public String getHighlights() {
		return highlights;
	}

	public void setHighlights(String highlights) {
		this.highlights = highlights;
	}

	public Business getBusiness() {
		return business;
	}

	public void setBusiness(Business business) {
		this.business = business;
	}

	public Bitmap getPicture() {
		return picture;
	}

	public void setPicture(Bitmap picture) {
		this.picture = picture;
	}
	
	public void save(DBHelper helper){
		DealDB ddb = new DealDB(helper);
		ddb.saveDeal(this);
	}

/////////////Parcelable//////////////////////////////
	
	

	private void readFromParcel(Parcel in) {
		// TODO Auto-generated method stub
		title = in.readParcelable(Title.class.getClassLoader());
		price = in.readParcelable(Price.class.getClassLoader());
		ending_time = in.readParcelable(ParcelableDate.class.getClassLoader());
		conditions = in.readString();
		highlights = in.readString();
		business = in.readParcelable(Business.class.getClassLoader());
		picture = in.readParcelable(Bitmap.class.getClassLoader());
		
	}
	@Override
	public void writeToParcel(Parcel dest, int flags) {
		// TODO Auto-generated method stub
		dest.writeParcelable(title,flags);
		dest.writeParcelable(price, flags);
		dest.writeParcelable(ending_time,flags);
		dest.writeString(conditions);
		dest.writeString(highlights);
		dest.writeParcelable(business, flags);
		dest.writeParcelable(picture, flags);
	}	
	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}
	
	@SuppressWarnings("rawtypes")
	public static final Parcelable.Creator CREATOR =
    	new Parcelable.Creator() {
            public Deal createFromParcel(Parcel in) {
                return new Deal(in);
            }
 
            public Deal[] newArray(int size) {
                return new Deal[size];
            }
        };
	
	///////////////////////////////////////////////////////
	
        
	

}
